package org.infodavid.common.model.impl;

import org.infodavid.common.model.components.IEMail;
import org.infodavid.common.model.impl.AbstractBasicDataObjectImpl;

/**
 * The Class EMailImpl.
 */
public class EMailImpl extends AbstractBasicDataObjectImpl implements IEMail {

	/** serialVersionUID. */
	private static final long serialVersionUID = 8567730969539674513L;

	/** The type. */
	private IEMail.EMailType type;

	/** The value. */
	private String value;

	/**
	 * The Constructor.
	 * @throws Exception the exception
	 */
	protected EMailImpl() throws Exception {
		super();
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.IEMail#getValue()
	 */
	@Override
	public String getValue() {
		return value;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.IEMail#setValue(java.lang.String)
	 */
	@Override
	public void setValue(final String arg0) {
		if (!equals(value, arg0)) {
			value = arg0;
			markModified(VALUE);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.IEMail#getType()
	 */
	@Override
	public EMailType getType() {
		return type;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.IEMail#setType(org.infodavid.common.model
	 * .entities.IEMail.EMailType)
	 */
	@Override
	public void setType(final EMailType arg0) {
		if (!equals(type, arg0)) {
			type = arg0;
			markModified(TYPE);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.IBasicDataObject#init()
	 */
	@Override
	public void init() throws Exception {
		super.init();

		type = null;
		value = null;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;

		result = prime * result + (getValue() == null ? 0 : getValue().hashCode());

		return result;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}

		if (obj == null) {
			return false;
		}

		if (!(obj instanceof IEMail)) {
			return false;
		}

		final IEMail other = (IEMail)obj;

		if (getValue() == null) {
			if (other.getValue() != null) {
				return false;
			}
		}
		else if (!getValue().equals(other.getValue())) {
			return false;
		}

		return true;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.impl.BasicDataObjectImpl#toString(java.lang.StringBuffer)
	 */
	@Override
	protected StringBuffer toString(final StringBuffer builder) {
		super.toString(builder);

		builder.append(", type=");
		builder.append(type);
		builder.append(", value=");
		builder.append(value);

		return builder;
	}
}
